<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="./js/promiseajax.js"></script>
</head>

<body>
    <form action="">
        用户名:<input type="text" name="username">
        <br>
        密码:<input type="password" name="password">
        <br>
        邮箱:<input type="text" name="email">
        <br>
        <input type="submit">
    </form>

</body>
<script>
    var form = document.querySelector('form')
    form.onsubmit = function () {
        var ipts = document.querySelectorAll('input')
        var username = ipts[0].value
        var password = ipts[1].value
        var email = ipts[2].value
        request({
            url: '/api/users/register',
            method: 'post',
            data: {
                username,
                password,
                email
            }
        }).then((res) => {
            // console.log(res);
            let {error_code,msg}=res
            alert(msg)
            if(error_code===0){
                location.href='./login.html'
            }
        })

        return false
    }
</script>